package Smallprogram.servict.impl;

import Smallprogram.dao.impl.BreakfastItemDaoImpl;
import Smallprogram.entiy.BreakfastItem;
import Smallprogram.entiy.Directory;
import Smallprogram.servict.BreakfastItemServlet;

import java.util.ArrayList;
import java.util.List;

public class BreakfastItemServletImpl  implements BreakfastItemServlet {
    BreakfastItemDaoImpl bae= new BreakfastItemDaoImpl();
    @Override
    public List<BreakfastItem> selist() {
        return bae.selectClasslist();
    }

    @Override
    public List<BreakfastItem.Goods> selistlisr() {
        return bae.selectSnacks();
    }

    @Override
    public List<BreakfastItem.Goods.Entity> selistliMnae() {
        return bae.selistliMnae();
    }

    @Override
    public int selectLien() {
        return bae.selectLien();
    }

    @Override
    public List<BreakfastItem> selectSnacrkByClass() {
        List<BreakfastItem> classList=bae.selectClasslist();
        List<BreakfastItem.Goods> goods=bae.selectSnacks();
        for (int i =0 ; i <classList.size(); i ++){
            int classId = classList.get(i).getId();

            for (int x=0;  x < goods.size(); x++){
                if(classId==goods.get(x).getType()){
                    List<BreakfastItem.Goods> tempList=classList.get(i).getGoodsList();
                    if(tempList==null){
                        tempList = new ArrayList<>();
                    }
                    tempList.add(goods.get(x));
                    classList.get(i).setGoodsList(tempList);
                }
            }


        }


        return classList;
    }

    @Override
    public List<Directory> selectlist() {
        return bae.selectlist();
    }

    public   List<BreakfastItem> selectlise(){
        List<BreakfastItem.Goods.Entity> listEntity=selistliMnae();
        List<BreakfastItem.Goods> listGoods=selistlisr();
        List<BreakfastItem>listRes=selist();
        List<Directory> list=selectlist();
        List<BreakfastItem>listiem=new ArrayList<>();
     for (int i=0;i<selectLien();i++){
         int iw=6905;
         List<BreakfastItem.Goods.Entity> listEntit=new ArrayList<>();
         List<BreakfastItem.Goods>listgods=new ArrayList<>();
         listEntit.add(listEntity.get(i));
         BreakfastItem.Goods goods=listGoods.get(i);
         Directory directo = list.get(i);
         listgods.add(new BreakfastItem.Goods(goods.getSellTimeStatus(), goods.getId(),goods.isSell(),goods.getPackCost(),goods.getSales(),goods.getGoodsType(),goods.getCoverImg(),goods.getProperty(),goods.getGoodsMealsInfo(),goods.getIsAdd(),goods.isUseSpec(),listEntit,goods.getStallCode(),goods.getSort(),goods.getPrice(),goods.getUnit(),goods.getImageArr(),goods.getMembershipPrice(),goods.getUseProperty(),goods.getUnitType(),goods.getMinBuyNum(),goods.getSpecs(),goods.getContent(),goods.getIsFollowSuit(),goods.getStock(),goods.getType(),goods.getIsLabel(),goods.getName(),goods.getImages()));
         listiem.add(new BreakfastItem(directo.getDirectoryid(),"",iw,listgods,directo.getDirectoryname(),0));
         iw++;
     }
     return listiem;
    }
}
